= content_for(:heading_toolbar) do
  .financial-year-title{ class: "#{resource.state}-financial-year"}
    %h2= resource.state.t(scope: 'enumerize.financial_year.state')

- main_toolbar do |t|
  - unless resource.closing? || resource.closed? || resource.locked?
    = t.edit resource unless resource.closure_in_preparation? && @closer != current_user

  = t.new(label: :new_financial_year_exchange.tl, params: { controller: :financial_year_exchanges, financial_year_id: resource.id }) if resource.can_create_exchange? && resource.opened?

  - if resource == FinancialYear.closable_or_lockable && !resource.closure_in_preparation?
    = link_to :prepare_financial_year_for_closure.tl(code: resource.code), { controller: :financial_year_closure_preparations, action: :create, financial_year_id: resource.id, redirect: backend_financial_year_path(resource) }, { class: 'btn btn-default no-icn', method: :post } unless resource.exchanges.opened.any?
    = t.lock resource, label: :lock_financial_year.tl(code: resource.name), icon: false

  - if resource.closure_in_preparation? && @closer == current_user
    = link_to :quit_financial_year_closure_preparation.tl(code: resource.code), { controller: :financial_year_closure_preparations, action: :destroy, financial_year_id: resource.id, redirect: backend_financial_year_path(resource) }, { class: 'btn btn-default no-icn', method: :delete }
    = t.close resource, label: :close_financial_year.tl(code: resource.name), icon: false
    = t.lock resource, label: :lock_financial_year.tl(code: resource.name), icon: false

  - style = resource.closing? ? 'disabled-btn' : ''
  = dropdown_menu_button(:export_fec.ta, { icon: :download }) do |d|
    - export_params = params.slice(:id)
    - %i[text xml].each do |format|
      - %i[all ba_bnc_ir_commercial_accountancy ba_ir_cash_accountancy bnc_ir_cash_accountancy].each do |position|
        - d.item "export_#{format}_fec_#{position}".tl, action: :show, fiscal_position: position, format: format

  = t.export :income_statement, :balance_sheet, :short_balance_sheet, key: Printers::BalanceSheetPrinter.build_key(financial_year: resource)

= main_informations attachment: true do
  = infos do
    .med-info.important
      %span.title= :year_start.tl
      %span.value= resource.started_on.l

    .med-info.important
      %span.title= :year_end.tl
      %span.value= resource.stopped_on.l

    .med-info.important
      %span.title= :currency.t(scope: 'preferences')
      %span.value= Nomen::Currency.find(resource.currency).human_name.upcase

    - if resource.closed? && resource.archives.any?
      - ['prior_to', 'post'].each do |timing|
        .med-info.important
          %span.title= "archive_#{timing}_closure".tl
          = link_to backend_financial_year_archive_path(resource, timing: "#{timing}_closure"), method: :post do
            %button.btn.btn-default.icn.btn-download= :download_archive.tl
          %br
          %span.signature-trigger
            %i.lock-picto
            = :this_archive_is_digitally_signed.tl
            %i.chevron
          .signature-details
            .signature-title= :fingerprint_sha256.tl
            = resource.send("#{timing}_closure_archive").sha256_fingerprint
            - signature_for_url = resource.send("#{timing}_closure_archive").signature.gsub(/\n/, '¤').gsub(/\+/, '§')
            .signature-title= t('labels.signature_html', url: "#{FinancialYearArchive::PUBLIC_KEY_URL}?signature=#{signature_for_url}")
            = resource.send("#{timing}_closure_archive").signature.gsub(/\n/, '<br />').html_safe

  = render 'progress', value: @progress_status[:value], resource: resource, refresh: false, current_step: @progress_status[:step], steps_count: @progress_status[:total], step_label: @progress_status[:label]

= cobbles do |c|
  -# c.cobble(resource.closed ? :balance : :last_computed_balance) do
    = cobble_list :account_balances

  -# c.cobble(:fixed_asset_depreciations) do
    = cobble_list :fixed_asset_depreciations

  - c.cobble(:exchanges) do
    = cobble_list :exchanges
